package pw.hais.app;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.google.gson.Gson;

import pw.hais.ui.LoadProgressDialog;
import pw.hais.utils.ViewHolderUtils;


/**
 * 基础Activity
 * Created by hais1992 on 15-5-6.
 */
public class AppBaseActivity extends FragmentActivity implements LoadProgressDialog.LoadDialog {
    protected String tag = "";              //当前TAG
    protected AppBaseActivity context;              //方便设置监听器等。。
    protected Gson gson = UtilConfig.GSON;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tag = getClass().getSimpleName();   //获取 当前类名，方便 打log
        ((AppApplication) getApplication()).addActivity(this);
        context = this;
    }

    public boolean isDrawFinish = false;

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if (hasFocus && !isDrawFinish) {
            isDrawFinish = true;
            onDrawFinish();
        }
    }

    /**
     * 渲染完毕
     */
    public void onDrawFinish() {

    }


    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        if (UtilConfig.IS_NO_FIND_VIEW) ViewHolderUtils.initViews(this);   //反射获取 类中的 View
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void finish() {
        super.finish();
        ((AppApplication) getApplicationContext()).removeActivity(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    /*----------------------------加载弹出窗------------------------------------*/
    public LoadProgressDialog loadDialog;    //菊花

    @Override
    public void loadDialogShow(String text) {
        if (loadDialog == null) {
            loadDialog = new LoadProgressDialog(this);
        }
        if(this.isDestroyed())loadDialog.show(text);
    }
    public void loadDialogShow(int text) {
        if (loadDialog == null) {
            loadDialog = new LoadProgressDialog(this);
        }
        if(this.isDestroyed())loadDialog.show(getString(text));
    }

    @Override
    public void loadDialogDismiss() {
        if (loadDialog != null) loadDialog.dismiss();
    }

}
